<template>
  <div id="box">
    <!-- <img src="../assets//images//bg.jpg" alt="" style="max-width: 100%;max-height: 100%;"> -->
    <div id="login">
      <div id="l-box">
        <h2>供应链</h2>
        <p style="margin: 0">
          <i class="el-icon-user-solid"></i>
          <!-- <input placeholder="账号" type="text" v-model="loginUser.loginName"> -->
          <el-input v-model="loginUser.loginName" placeholder="账号"></el-input>
        </p>
        <p>
          <i class="el-icon-lock"></i>
          <!-- <input placeholder="密码" type="password" v-model="loginUser.password"> -->
          <el-input
            v-model="loginUser.password"
            type="password"
            placeholder="密码"
            show-password
          ></el-input>
        </p>
        <!-- <p>
          <el-select
            style="width: 160px"
            v-model="loginUser.cid"
            placeholder="请选择公司"
          >
            <el-option
              v-for="item in relations"
              :key="item.relationId"
              :label="item.relationName"
              :value="item.relationId"
            >
            </el-option>
          </el-select>
        </p> -->
        <p>
          <el-row>
            <el-button
              id="login-btn"
              v-loading="showFlag"
              type="primary"
              @click="doLogin"
              >登录</el-button
            >
          </el-row>
        </p>
        <router-link
          style="color: #c77869; position: relative; left: 150px; top: 20px"
          to="register"
          >点我注册</router-link
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      relations: [],
      loginUser: {
        loginName: "",
        password: "",
        cid: "",
      },
      showClose: false,
      showFlag: false,
    };
  },
  created() {
    this.getrelations();
  },
  methods: {
    getrelations() {
      this.axios({
        url: "/info/relation/selectCompany",
      }).then((rs) => {
        this.relations = rs.data.company;
      });
    },
    goto(to) {
      this.$router.push(to);
    },
    doLogin() {
      if (this.loginUser.password === "" || this.loginUser.loginName === "") {
        alert("请填写完整信息！");
        return;
      }
      this.axios
        .post("/info/login", {
          employeeCode: this.loginUser.loginName,
          password: this.loginUser.password,
        })
        .then((rs) => {
          console.log(rs);
          if (rs.data.code == 200) {
            alert("登录成功!");
            window.sessionStorage.setItem("token", rs.data.token);
            window.sessionStorage.setItem("employeeCode", rs.data.employeeCode);
            window.sessionStorage.setItem("cid", rs.data.cid);
            this.goto("chart");
          } else {
            alert("登录失败!");
          }
        });
    },
  },
};
</script>

<style scoped>
#box {
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  background-image: url(../../assets/image/bg.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}

#l-box {
  width: 100%;
  height: 280px;
  background-color: white;
}

.el-input {
  margin-left: 10px;
}

#login {
  width: 480px;
  margin: auto;
  position: relative;
  top: 70px;
  text-align: center;
  border-radius: 30px;
  overflow: hidden;
}

.el-input {
  width: 240px;
  margin-bottom: 10px;
}

#login input {
  width: 240px;
  height: 34px;
  font-size: 16px;
  padding-left: 10px;
  border: 1px solid #a5a6a7;
  /* border: none;
  border-bottom: 1px solid gray; */
  margin-left: 10px;
  outline: none;
}

/* .el-input--suffix .el-input__inner {
  position: relative;
  left: 50px;
} */

#l-box h2 {
  margin: 0;
  padding: 0;
  position: relative;
  top: -70px;
  color: #c77869;
}

#l-box {
  padding-top: 100px;
}

#login-btn {
  background-color: #c77869;
  border: none;
  width: 180px;
  margin-top: 30px;
  height: 40px;
}
</style>